import typeMap from '@/components/Form/utils/type-map';
import typeValue from '@/components/Form/utils/type';

/**
 * @export 获取表单基础属性
 * @param {*} {
 *   required, 必填
 *   label, 字段说明
 *   placeholder, 提示
 *   value 值
 *   id 表单唯一标识
 *   search 表单数据关联
 *   ref_child 关联表单
 * }
 * @return {*}
 */
export default function getProp({ fields }) {
  const {
    verification,
    setting,
    title,
    field_type,
    value,
    id = Math.random().toString(),
    collectProps = {},
    can_do,
    remote,
    search = {},
    remote_url = '',
    ref_child = [],
    type: form_type
  } = fields;
  const { required } = verification;
  const { tips, d_type, read_only } = setting;
  const { number } = typeValue;

  return {
    required: !!required,
    label: title || field_type,
    name: field_type || title,
    placeholder: tips || '',
    value: value || '',
    search,
    id,
    form_type,
    can_do: !can_do,
    d_type: typeMap[d_type] === number.type ? number.type : 'text',
    disabled: !!read_only,
    remote: !!remote,
    remoteUrl: remote_url,
    collectProps,
    ref_child
  };
}
